package com.tron.thread.semaphore;

import lombok.SneakyThrows;

public class SemaphoreStart {

    public static void main(String[] args) {
        final BoundSource boundSource = new BoundSource(3);
        new UseThread(boundSource).start();
        new UseThread(boundSource).start();
        new UseThread(boundSource).start();
        new UseThread(boundSource).start();
    }

    public static class UseThread extends Thread{
        private BoundSource boundSource;

        public UseThread(BoundSource boundSource) {
            this.boundSource = boundSource;
        }

        @SneakyThrows
        public void run() {
            while (true) {
            boundSource.use();
            }
        }
    }
}
